import turtle
import math

# 设置画布
screen = turtle.Screen()
screen.title("夸父逐日")
screen.setup(width=1000, height=600)
screen.bgcolor("#87CEEB")  # 天空蓝色

# 创建画笔
pen = turtle.Turtle()
pen.speed(3)  # 绘图速度
pen.hideturtle()

# 绘制太阳
def draw_sun():
    pen.penup()
    pen.goto(300, 150)
    pen.pendown()
    
    # 太阳主体
    pen.color("#FFD700", "#FFA500")
    pen.begin_fill()
    pen.circle(50)
    pen.end_fill()
    
    # 太阳光芒
    pen.color("#FFD700")
    for _ in range(12):
        pen.penup()
        pen.goto(300, 200)
        pen.pendown()
        pen.setheading(_ * 30)
        pen.forward(30)

# 绘制远山
def draw_mountains():
    # 远山
    pen.penup()
    pen.goto(-500, -100)
    pen.pendown()
    pen.color("#228B22", "#2E8B57")
    pen.begin_fill()
    for x in range(-500, 500, 50):
        y = -100 - math.sin(x/50) * 80
        pen.goto(x, y)
    pen.goto(500, -300)
    pen.goto(-500, -300)
    pen.goto(-500, -100)
    pen.end_fill()
    
    # 近山
    pen.penup()
    pen.goto(-500, -150)
    pen.pendown()
    pen.color("#3CB371", "#4CAF50")
    pen.begin_fill()
    for x in range(-500, 500, 30):
        y = -150 - math.sin(x/30) * 50
        pen.goto(x, y)
    pen.goto(500, -300)
    pen.goto(-500, -300)
    pen.goto(-500, -150)
    pen.end_fill()

# 绘制地面和河流
def draw_ground():
    # 地面
    pen.penup()
    pen.goto(-500, -100)
    pen.pendown()
    pen.color("#8B4513", "#A0522D")
    pen.begin_fill()
    pen.goto(500, -100)
    pen.goto(500, -300)
    pen.goto(-500, -300)
    pen.goto(-500, -100)
    pen.end_fill()
    
    # 河流
    pen.penup()
    pen.goto(-400, -150)
    pen.pendown()
    pen.color("#1E90FF", "#87CEFA")
    pen.begin_fill()
    for x in range(-400, 400, 20):
        y = -150 + math.sin(x/80) * 30
        pen.goto(x, y)
    pen.goto(400, -200)
    pen.goto(-400, -200)
    pen.goto(-400, -150)
    pen.end_fill()

# 绘制夸父
def draw_kuafu():
    pen.penup()
    pen.goto(-200, -50)
    pen.pendown()
    
    # 头部
    pen.color("#000000", "#FFDAB9")
    pen.begin_fill()
    pen.circle(30)
    pen.end_fill()
    
    # 眼睛
    pen.penup()
    pen.goto(-210, -30)
    pen.pendown()
    pen.color("#000000", "#FFFFFF")
    pen.begin_fill()
    pen.circle(5)
    pen.end_fill()
    
    pen.penup()
    pen.goto(-180, -30)
    pen.pendown()
    pen.begin_fill()
    pen.circle(5)
    pen.end_fill()
    
    # 身体
    pen.penup()
    pen.goto(-190, -60)
    pen.pendown()
    pen.color("#000000", "#8B4513")
    pen.begin_fill()
    pen.goto(-190, -120)
    pen.goto(-160, -120)
    pen.goto(-160, -60)
    pen.goto(-190, -60)
    pen.end_fill()
    
    # 左臂
    pen.penup()
    pen.goto(-190, -80)
    pen.pendown()
    pen.color("#000000", "#FFDAB9")
    pen.begin_fill()
    pen.goto(-230, -90)
    pen.goto(-220, -110)
    pen.goto(-180, -100)
    pen.goto(-190, -80)
    pen.end_fill()
    
    # 右臂
    pen.penup()
    pen.goto(-160, -80)
    pen.pendown()
    pen.begin_fill()
    pen.goto(-120, -70)
    pen.goto(-110, -90)
    pen.goto(-150, -100)
    pen.goto(-160, -80)
    pen.end_fill()
    
    # 左腿
    pen.penup()
    pen.goto(-190, -120)
    pen.pendown()
    pen.begin_fill()
    pen.goto(-210, -180)
    pen.goto(-190, -180)
    pen.goto(-180, -120)
    pen.goto(-190, -120)
    pen.end_fill()
    
    # 右腿
    pen.penup()
    pen.goto(-170, -120)
    pen.pendown()
    pen.begin_fill()
    pen.goto(-160, -180)
    pen.goto(-140, -170)
    pen.goto(-160, -120)
    pen.goto(-170, -120)
    pen.end_fill()
    
    # 手杖
    pen.penup()
    pen.goto(-120, -70)
    pen.pendown()
    pen.color("#8B4513", "#8B4513")
    pen.pensize(5)
    pen.setheading(60)
    pen.forward(100)
    pen.pensize(1)

# 绘制云朵
def draw_clouds():
    pen.color("#FFFFFF", "#FFFFFF")
    positions = [(-350, 150), (-100, 200), (200, 180)]
    
    for x, y in positions:
        pen.penup()
        pen.goto(x, y)
        pen.pendown()
        pen.begin_fill()
        for i in range(5):
            pen.circle(20)
            pen.penup()
            pen.forward(30)
            pen.pendown()
        pen.end_fill()

# 绘制标题
def draw_title():
    pen.penup()
    pen.goto(-150, 220)
    pen.pendown()
    pen.color("#8B0000")
    pen.write("夸父逐日", font=("SimHei", 30, "bold"))

# 组合绘制
draw_ground()
draw_mountains()
draw_clouds()
draw_sun()
draw_kuafu()
draw_title()

# 保持窗口打开
turtle.done()
